package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbSpeakers;
import com.ruoyi.teach.service.INbSpeakersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程主讲人/助教Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/speakers")
public class NbSpeakersController extends BaseController
{
    @Autowired
    private INbSpeakersService nbSpeakersService;

    /**
     * 查询课程主讲人/助教列表
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbSpeakers nbSpeakers)
    {
        startPage();
        List<NbSpeakers> list = nbSpeakersService.selectNbSpeakersList(nbSpeakers);
        return getDataTable(list);
    }

    /**
     * 导出课程主讲人/助教列表
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:export')")
    @Log(title = "课程主讲人/助教", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbSpeakers nbSpeakers)
    {
        List<NbSpeakers> list = nbSpeakersService.selectNbSpeakersList(nbSpeakers);
        ExcelUtil<NbSpeakers> util = new ExcelUtil<NbSpeakers>(NbSpeakers.class);
        util.exportExcel(response, list, "课程主讲人/助教数据");
    }

    /**
     * 获取课程主讲人/助教详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbSpeakersService.selectNbSpeakersById(id));
    }

    /**
     * 新增课程主讲人/助教
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:add')")
    @Log(title = "课程主讲人/助教", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbSpeakers nbSpeakers)
    {
        nbSpeakersService.insertNbSpeakers(nbSpeakers);
        return AjaxResult.success(nbSpeakers);
    }

    /**
     * 修改课程主讲人/助教
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:edit')")
    @Log(title = "课程主讲人/助教", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbSpeakers nbSpeakers)
    {
        return toAjax(nbSpeakersService.updateNbSpeakers(nbSpeakers));
    }

    /**
     * 删除课程主讲人/助教
     */
    @PreAuthorize("@ss.hasPermi('teach:speakers:remove')")
    @Log(title = "课程主讲人/助教", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbSpeakersService.deleteNbSpeakersByIds(ids));
    }
}
